<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%@ include file="./common/common.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>款号单价设定</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script type="text/javascript" src="js/jquery.js"language="javascript"></script>
    <script src='<%=basePath%>dwr/interface/proPriceService.js'></script>
    <script src="<%=basePath%>dwr/engine.js"></script>
    <script src="<%=basePath%>dwr/util.js"></script>
    
           <script type="text/javascript" language="javascript">
             function del(proPriceId){
               if(confirm("确定要删除编号为:"+proPriceId+"的设置吗?")){
                proPriceService.removeStylePrice(proPriceId,function(i){
                  if(i>0){
                   $("#"+proPriceId).remove();
                   alert("删除成功!");
                  }else{
                   alert("删除失败!");
                  }
                });
               }else return;
             }
             
             function selectList(){
               var wsId = $("#wsId").val();
               var proStyleNo = $.trim($("#proStyleNo").val());
               if(proStyleNo==""){
                 alert("查询款号不能为空");
                 return;  
               }
               $("#loading").removeAttr("style");
               proPriceService.queryStylePriceListByClause(wsId,proStyleNo,callbackFunction);
             }
             
             var callbackFunction = function(data){
              
              $("#result").empty();
              var appendData = "<table border='1' width='100%' id='resultTable'>";
               appendData+="<tr>";
               appendData+="<th>工序</th>";
               appendData+="<th>款号</th>";
               appendData+="<th>单价</th>";
               appendData+="<th>操作</th>";
               appendData+="</tr>";
             for(var property in data){ 
               appendData+="<tr id='"+data[property].proId+"'>";
               appendData+="<td>"+data[property].wsName+"</td>";
               appendData+="<td><input type='text' onchange=this.style.backgroundColor='#E5F0FF'; id='Style"+data[property].proId+"' value='"+data[property].proStyleNo+"' /></td>";
               appendData+="<td><input type='text' onchange=this.style.backgroundColor='#E5F0FF'; id='Price"+data[property].proId+"' value='"+data[property].price+"' /></td>";
               
               appendData+="<td><input type='button' value='删除' onclick='del("+data[property].proId+")'/>";
               appendData+="<input type='button' value='修改' onclick='update("+data[property].proId+")'/></td>";
               appendData+="</tr>";
             }
             appendData+="</table>";
             $("#result").append(appendData);    
             }
             
             function create(){
               var wsName = $("#wsId").val();
               var proStyleNo = $.trim($("#proStyleNo").val());
               var price = $.trim($("#price").val());
               if(wsName==""||proStyleNo==""){
                 alert("工序或款号不能为空!");
                 return;
               }else{
                 proPriceService.regStylePrice({price:price,wsId:wsName,proStyleNo:proStyleNo},function(i){
                   if(i==1){
                     alert("新增成功!");
                     $("#wsId").attr("value",'');
                     $("#proStyleNo").attr("value",proStyleNo);
                     $("#price").attr("value",'');
                     selectList();
                   }else if(i==0){
                     alert("新增失败!已存在编号为"+id+"的设置!");
                   }else{
                     alert("新增失败!");
                   }
                 });
               }
             }
             
             function update(Id){
               //var wsName = $.trim($("#Style"+Id).val());
               var proStyleNo = $.trim($("#Style"+Id).val());
               var price = $.trim($("#Price"+Id).val());
              if(price==""||proStyleNo==""){
                 alert("价格或款号不能为空!");
                 return;
               }else{
                 proPriceService.updateStylePrice({propriceId:Id,proStyleNo:proStyleNo,price:price},function(i){
                   if(i==1){
                     alert("修改成功!");
                     $("#Style"+Id).removeAttr("style");
                     $("#Price"+Id).removeAttr("style");
                   }else{
                     alert("修改失败!");
                   }
                 });
               }
             }
             
             function importFile(){
               var file1 = $("#file1").val();
               $("#loading").removeAttr("style");
               $("#import").attr("disabled","disabled");
               proPriceService.ImportExcel(file1,function(a){
                if(a>0)alert("成功导入"+a+"条记录!");
                else alert("导入失败!");
                $("#import").removeAttr("disabled");
                $("#loading").attr("style","display:none");
                $("#file1").attr("value","");
               });
             }
           </script>
  </head>
  
  <body>
    <h1>款式单价设定</h1>
    <hr>
    
    款式编号:<input id=proStyleNo type="text"/>
    <p>工序:<select id="wsId">
             <option></option>
             <c:forEach var="ws" items="${wsDataList}">
                  <option value="${ws.wsId}">${ws.wsName}</option>
             </c:forEach>
            </select>
    <p>单价:<input id="price" type="text"/>
    <p>Excel导入:<input type="file" name=file1 id="file1" >
       <input id="import" type="button" value="导入" onclick="importFile()">
       <a href="<%=basePath%>OrderExcel/proPriceModel.xls">模板下载</a>
    </p>
    <p>
       <input id="select" type="button" value="查询" onclick="selectList()"/>
       <input id="new" type="button" value="新增" onclick="create()"/>
    <hr>
    <div id="result">
     <img id="loading" src="img/loading.gif" style="display:none">
    </div>
  </body>
</html>
